#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject
@File    : yamlRead.py
@IDE     : PyCharm
@Author  : Mario
@Date    : 2022/4/20 16:00
@Describe: YAML文件读取
"""
import os
import yaml


class YamlRead:

    def __init__(self):
        """构造函数"""
        # 相对定位匹配配置文件位置
        _configDir = os.path.dirname(__file__)
        _configFile = os.path.join(_configDir, 'config.yaml')
        # 读取配置文件
        with open(_configFile, 'rb') as yamlFile:
            yaml_file_reader = yamlFile.read()
            self._yamlResultData = yaml.load(yaml_file_reader, yaml.FullLoader)

    def reader_yaml_data(self, config_item):
        """
        获取YAML文件配置信息
        :param config_item: 需要获取的键
        :return: 返回对应键下面的所有配置信息
        """
        _itemConfigData = self._yamlResultData[config_item]
        return _itemConfigData


# 将各配置读取出来，放在变量里面，后续其他文件直接引用这些变量
config = YamlRead()
sys_cfg = config.reader_yaml_data('sys')
log_cfg = config.reader_yaml_data('log')
smtp_cfg = config.reader_yaml_data('smtp')
email_cfg = config.reader_yaml_data('email')
deviceInfo_cfg = config.reader_yaml_data('deviceInfo')
interfaceName_cfg = config.reader_yaml_data('interfaceName')
middleLoginInfo_cfg = config.reader_yaml_data('middleLoginInfo')
mysqlInfo_cfg = config.reader_yaml_data('mysqlInfo')
workWeiXin_cfg = config.reader_yaml_data('workWeiXin')
miniProgramInfo_cfg = config.reader_yaml_data('miniProgramInfo')
brandCode_cfg = config.reader_yaml_data('brandCode')
if __name__ == '__main__':
    print(brandCode_cfg)
